//go:build wireinject
// +build wireinject

package wire

import (
	"context"
	"embed"
	"github.com/google/wire"
	"go.uber.org/zap"
	"onvif_server/internal/handler"
	"onvif_server/internal/library/setting"
	"onvif_server/internal/repository"
	"onvif_server/internal/server"
	"onvif_server/internal/service"
	"onvif_server/old_api"
	"onvif_server/pkg/app"
	"onvif_server/pkg/db"
	"onvif_server/pkg/jwt"
	"onvif_server/pkg/onvif"
	"onvif_server/pkg/server/http"
	"onvif_server/pkg/subscribe"
	"onvif_server/pkg/ws"
	"onvif_server/pkg/zlmedia_sdk"
	"time"
)

var pkgSet = wire.NewSet(
	db.NewDB,
	jwt.NewJwt,
	onvif.NewOnvif,
	setting.NewSetting,
	zlmedia_sdk.NewZLMediaClient,
	subscribe.NewSubscribe,
	ws.NewManage,
	//events.NewEvent,
)

var repositorySet = wire.NewSet(
	repository.NewRepository,
	repository.NewTransaction,
	repository.NewUserRepository,
	repository.NewCameraRepository,
	repository.NewSubscriptionRepository,
	repository.NewSettingRepository,
	repository.NewAlarmRepository,
)

var serviceSet = wire.NewSet(
	service.NewService,
	service.NewUserService,
	service.NewCameraService,
	service.NewSubscriptionService,
	service.NewSettingService,
	service.NewAlarmService,
	service.NewSystemService,
)

var handlerSet = wire.NewSet(
	handler.NewHandler,
	handler.NewAssetsHandler,
	handler.NewUserHandler,
	handler.NewCameraHandler,
	handler.NewSubscriptionHandler,
	handler.NewCommonHandler,
	handler.NewSettingHandler,
	handler.NewAlarmHandler,
	handler.NewSystemHandler,
	//兼容旧的外部接口
	old_api.NewOldApiHandler,
)

var serverSet = wire.NewSet(
	server.NewHTTPServer,
	//server.NewJob,
	server.NewTask,
	server.NewDiscovery,
)

// build App
func newApp(httpServer *http.Server, taskServer *server.Task, discoveryServer *server.Discovery) *app.App {
	return app.NewApp(
		app.WithServer(httpServer, taskServer, discoveryServer),
		app.WithName("onvif"),
	)
}

func NewWire(context.Context, string, *time.Location, *zap.Logger, *embed.FS, *db.Config, *http.Config, *jwt.Config, *server.Config, *zlmedia_sdk.Config, *subscribe.Config, *service.Config, *server.DiscoveryConfig) (*app.App, func(), error) {
	panic(wire.Build(
		pkgSet,
		repositorySet,
		serviceSet,
		handlerSet,
		serverSet,
		newApp,
	))
}
